﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using Hiram.Redis;
using NewLife.Configuration;
using NewLife.Log;
using NewLife.Serialization;
using Newtonsoft.Json;
using ProtoBuf;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //test

            var auth = Config.GetConfig<string>("auth");
            if (auth.IsNullOrWhiteSpace())
            {
                XTrace.Log.Error("auth is nil");
                return;
            }
            BufferPool.DEFAULT_BUFFERLENGTH = 1024 * 200;//默认200k


            var pain = new PaInfo(){ Id = 2, Name = "张三", Time =DateTime.Now};
            var rds = new RedisClient(auth)
            {
                DB = 1
            };

           var resp= rds.Info("memory", DataType.String);

            var res=rds.LPUSH("1", pain, DataType.Json);
            XTrace.Log.Info($"插入{(res > 0 ? "成功" : "失败")}");
            var query = rds.ListRange<PaInfo>("1", DataType.Json)?.FirstOrDefault();
            XTrace.Log.Info($"序号：{query.Id},名称：{query.Name},时间：{query.Time}");
           // Console.ReadKey();
            rds.Set("2", pain, DataType.Protobuf);
            var x=rds.Get<PaInfo>("2", DataType.Protobuf);
        }
    }
    [DataContract]
    [Serializable]
    [ProtoContract(SkipConstructor = true)]

    public class PaInfo
    {
        [ProtoMember(1)]
        [DataMember]
        public int Id { get; set; }
        [ProtoMember(2)]
        [DataMember]
        public string Name { get; set; }
        [ProtoMember(3)]
        [DataMember]
        public DateTime Time { get; set; }
    }

}
